﻿using BuildPlanner.Classes;
using BuildPlannerLib;
using BuildPlannerLib.Enums;
using BuildPlannerLib.PlayerActions;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Input;

namespace BuildPlanner
{
    public class DataContextSelect : DataContextBase
    {
        public List<string> MapSelectOptions { get; set; }

        private string mapSelectValue;
        public string MapSelectValue
        {
            get { return mapSelectValue; }
            set
            {
                if (mapSelectValue != value)
                {
                    mapSelectValue = value;
                    NotifyPropertyChanged("MapSelectValue");
                }
            }
        }

        private Race race;
        public Race Race
        {
            get { return race; }
            set
            {
                if (race != value)
                {
                    race = value;
                    NotifyPropertyChanged("Race");
                }
            }
        }

        private Expansion expansion;
        public Expansion Expansion
        {
            get { return expansion; }
            set
            {
                if (expansion != value)
                {
                    expansion = value;
                    NotifyPropertyChanged("Expansion");
                }
            }
        }

        public Map Map { get; set; }
        public Build Build { get; set; }

        public RelayCommand StartNewBuildCommand { get; private set; }

        public DataContextSelect()
        {
            MapSelectOptions = new List<string>() { "Test" };
            MapSelectValue = "";

            StartNewBuildCommand = new RelayCommand(StartNewBuild, NewBuildCanExecute);
        }

        public bool NewBuildCanExecute(object parameter)
        {
            if (this.Race == Race.None)
                return false;
            if (this.Expansion == Expansion.None)
                return false;
            if (this.MapSelectValue == "")
                return false;
            return true;
        }

        private void StartNewBuild(object parameter)
        {
        }

        internal void NewBuild()
        {
            string mapSelectString = MapSelectValue.Replace(" ", "");
            mapSelectString = mapSelectString.Replace("(", "");
            mapSelectString = mapSelectString.Replace(")", "");
            MapSelect mapSelect = (MapSelect)Enum.Parse(typeof(MapSelect), mapSelectString, true);
            Map = new Map(mapSelect);
            Build = new Build(Race, Expansion, Map);
        }
    }
}
